package routers

import (
	"github.com/astaxie/beego"
)

/**
 * 路由入口文件，定义各种路由以及拦截器
 */

const (
	MY_Route      = iota //普通路由
	MY_Auto_Route        //自动路由
)

//路由结构体
type RouterStruct struct {
	Method         int
	C              beego.ControllerInterface
	Rootpath       string
	MappingMethods string
}

//过滤器结构体
type FilterStruct struct {
	Pattern string
	Pos     int
	Filter  beego.FilterFunc
}

type Bootstrap struct {
	Routs   []RouterStruct
	Filters []FilterStruct
}

//初始化路由和过滤器配置
func (b *Bootstrap) Init() {
	for _, i_route := range b.Routs {
		if i_route.Method == MY_Route {
			beego.Router(i_route.Rootpath, i_route.C, i_route.MappingMethods)
		} else {
			beego.AutoRouter(i_route.C)
		}
	}
	for _, i_filter := range b.Filters {
		beego.InsertFilter(i_filter.Pattern, i_filter.Pos, i_filter.Filter)
	}
}
